package jsu.lipengcheng.trafficnet.controlle.user;

import jsu.lipengcheng.trafficnet.common.BeanThread;
import jsu.lipengcheng.trafficnet.common.Result;
import jsu.lipengcheng.trafficnet.common.UserUpdataPassword;
import jsu.lipengcheng.trafficnet.common.Userlogin;
import jsu.lipengcheng.trafficnet.pojo.Users;
import jsu.lipengcheng.trafficnet.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
//@CrossOrigin(origins = "http://localhost:5173", allowCredentials = "true")
public class UserControlle {
    @Autowired
    private UserService userService;

    /**
     * 登录
     * @param users
     * @return
     */
    @PostMapping("login")
    public Result login(@RequestBody Users users) {
        Userlogin userlogin= userService.login(users);
        return Result.success(userlogin);
    }

    /**
     * 注册
     * @param users
     * @return
     */
    @PostMapping("/register")
    public Result register(@RequestBody Users users) {
        userService.register(users);
        return Result.success();
    }

    /**
     * 查询用户所有私人信息
     * @return
     */
    @GetMapping
    public Result getUsers() {
        Integer id = BeanThread.get();
        Users users = userService.selectuser(id);
        return Result.success(users);
    }

    /**
     * 修改密码
     * @param userUpdataPassword
     * @return
     */
    @PutMapping("/password")
    public Result updatePassword(@RequestBody UserUpdataPassword userUpdataPassword) {
        userService.updatapassword(userUpdataPassword);
        return Result.success();
    }

}
